function compileGraphsPDF(handleMat,fileName,filePath)
% function compileGraphsPDF(handleMat,fileName,filePath)
%
% Given the matrix of graphic handles in handleMat 
% Save them in the path filePath with the name fileNane, by first 
% appending them to a ps file and then converting the ps file into a pdf
% file. 
% A. Justiniano Jan 9 2012
fileName=char(fileName); 
fileName=regexprep(fileName,'-','_'); 
%fileName=regexprep(fileName,'.','_'); 
fileName=regexprep(fileName,'\',' ');
fileName=regexprep(fileName,'/',' '); 
handleMat=handleMat(:); 
handleMat=handleMat( handleMat > 0); 
cucd=cd; 
namePS=strcat(char(fileName),'.ps'); 
%namePS=regexprep(namePS,'-','_'); 
deleteFile(namePS,filePath); 
cd(filePath); 

for ii=1:length(handleMat); 
    if ii==1 
        print(handleMat(ii),'-dps',char(fileName));
    else
        print(handleMat(ii),'-dpsc',char(fileName),'-append');
    end
%     pause(2)
ii
end 

namePDF=strcat(char(fileName),'.pdf'); 
%namePDF=regexprep(namePDF,'-','_'); 
try 
ps2pdf('psfile',namePS,'pdffile',namePDF); %,'deletepsfile',1); 
catch 
    disp('Could not compile to PDF')     
end 
%ps2pdf_new(namePS,namePDF)
cd(cucd); 
end